package ncorps.fourier;

import ncorps.commun.ConditionInitiale;
import java.io.IOException;

public class NCorps_Fourier {

    private double dt;
    private ConditionInitiale CI;
    private double[][] gcoord;

    public NCorps_Fourier(ConditionInitiale CI, double dt) throws IOException {
        this.CI = CI;
        gcoord = CI.getGcoord();
        this.dt = dt;

        gcoord = calcul();
    }

    public double[][] calcul() {
        PotentielGrille potentielgrille = new PotentielGrille(CI);
        Interpolation PotentielInterpolation = new Interpolation(CI, potentielgrille);
        double[][] fforces = PotentielInterpolation.getGradientPotentielPourN();
        double[][] ngcoord = new double[CI.get_N()][5];

        for (int n = 0; n < CI.get_N(); n++) {
            ngcoord[n][1] = (((dt * dt) / 2) * fforces[n][0]) + (dt * gcoord[n][3]) + gcoord[n][1];
            ngcoord[n][3] = (dt * fforces[n][0]) + gcoord[n][3];
            ngcoord[n][2] = (((dt * dt) / 2) * fforces[n][1]) + (dt * gcoord[n][4]) + gcoord[n][2];
            ngcoord[n][4] = (dt * fforces[n][1]) + gcoord[n][4];
        }
        return ngcoord;
    }

    public double[][] getGcoord() {
        return gcoord;
    }
}
